package com.cti.commons.delayqueue.config;

import javax.annotation.PostConstruct;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import lombok.Data;

/**
 * @author et.wang
 * @description: 延时队列配置
 * @date 2022/10/28 14:19
 */
@Data
@Component
@ConfigurationProperties(prefix = "delay.queue")
public class DelayQueueConfig {

    private static DelayQueueConfig delayQueueConfig;

    /**
     * 桶默认大小
     */
    private static final int NUM = 10;

    /**
     * 扫描延迟任务桶名称
     */
    private String bucketJobName;

    /**
     * 扫描延迟队列名称
     */
    private String queueJobName;

    /**
     * 桶大小
     */
    private int bucketSize;

    @PostConstruct
    public void init() {
        delayQueueConfig = this;
        delayQueueConfig.bucketJobName = this.bucketJobName;
        delayQueueConfig.queueJobName = this.queueJobName;
        delayQueueConfig.bucketSize = this.bucketSize;
    }

    public static int getBucketSize() {
        return delayQueueConfig.bucketSize == 0 ? NUM : delayQueueConfig.bucketSize;
    }

    public static String getBucketJobName() {
        return delayQueueConfig.bucketJobName == null ? "delayQueue:delayBucket" : delayQueueConfig.bucketJobName;
    }

    public static String getQueueJobName() {
        return delayQueueConfig.queueJobName == null ? "delayQueue:delayQueueJobPool" : delayQueueConfig.queueJobName;
    }

}
